package org.ogv.usada.models;


public class Recipe {
	private RecipeDef 	_def;
	private boolean[]	_neededLeavesMask;
	private int			_leafLeft;
	
	public Recipe() {}
	
	public Recipe init(byte recipeId) {
		_def 				= Content.$().recipes[recipeId];
		_neededLeavesMask	= new boolean[_def.leafIds.length];
		resetLeaves();
		
		return this;
	}
	
	public boolean pushLeaf(byte leafId) {
		for(int i = 0; i < _def.leafIds.length; ++i) {
			if(_def.leafIds[i] == leafId && !_neededLeavesMask[i]) {
				_neededLeavesMask[i] = true;
				--_leafLeft;
				return true;
			}
		}
		
		//resetLeaves();
		return false;
	}
	
	public void resetLeaves() {
		for(int i = 0; i < _neededLeavesMask.length; ++i) {
			_neededLeavesMask[i] = false;
		}
		_leafLeft = _neededLeavesMask.length;
	}
	
	public boolean[] getMask() { return _neededLeavesMask; }
	public RecipeDef getDef() { return _def; }

	public boolean hasFulfilled() {
		return _leafLeft <= 0;
	}
}
